upgrade: context package upgrade for Solid 2.0#907
Conversation
🦋 Changeset detectedLatest commit: f6df19c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/context/test/index.test.tsx (1)
148-155: ⚡ Quick winAssert the specific strict-context failure, not just “any throw”.
.toThrow()will also pass on unrelated render failures, so this doesn't really lock down the advertisedContextNotFoundErrorcontract. Match the error name/message here so regressions stay visible.Suggested assertion tightening
expect(() => { render(() => { useStrict(); return ""; }, document.createElement("div")); - }).toThrow(); + }).toThrow(/ContextNotFoundError/);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/context/test/index.test.tsx` around lines 148 - 155, The test currently asserts any throw from rendering useStrict(), which is too broad; update the assertion to specifically expect the strict-context failure by asserting the thrown error is the ContextNotFoundError (or matches its exact name/message). Locate the test that calls createStrictContextProvider and invokes useStrict() in the render block, then replace the generic expect(...).toThrow() with an assertion that checks for ContextNotFoundError (e.g., toThrowError matching the error's name or exact message or using instanceof ContextNotFoundError) so the test fails on unrelated errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/context/src/index.ts`:
- Around line 54-60: Add an overload for createContextProvider that accepts
defaults: undefined so callers can pass an options object without a typed
default; specifically add a signature like createContextProvider<T, P extends
ContextProviderProps>(factoryFn: (props: P) => T, defaults: undefined, options?:
ContextProviderOptions): [provider: ContextProvider<P>, useContext: () => T |
undefined] (place this overload before the broader defaults:T overload to avoid
ambiguity), ensuring it matches the runtime behavior that allows (factoryFn,
undefined, options).
---
Nitpick comments:
In `@packages/context/test/index.test.tsx`:
- Around line 148-155: The test currently asserts any throw from rendering
useStrict(), which is too broad; update the assertion to specifically expect the
strict-context failure by asserting the thrown error is the ContextNotFoundError
(or matches its exact name/message). Locate the test that calls
createStrictContextProvider and invokes useStrict() in the render block, then
replace the generic expect(...).toThrow() with an assertion that checks for
ContextNotFoundError (e.g., toThrowError matching the error's name or exact
message or using instanceof ContextNotFoundError) so the test fails on unrelated
errors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: fc3a7746-eaf5-4850-aaa8-b0c5406cc244
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (8)
.changeset/context-solid2-migration.mdpackages/context/CHANGELOG.mdpackages/context/README.mdpackages/context/dev/index.tsxpackages/context/package.jsonpackages/context/src/index.tspackages/context/test/index.test.tsxpackages/context/test/server.test.tsx
Migrates
@solid-primitives/contextto Solid.js 2.0 (beta.13) and adds three quality-of-life additions to the API.Solid 2.0 migration (breaking)
Context.Providerremoved — In Solid 2.0, theContextobject itself is the provider component.createContextProviderandMultiProviderupdated;<MyCtx.Provider value={...}>becomes<MyCtx value={...}>.ContextProviderComponentimport fixed — Previously imported from an internalnode_modulespath; now a proper export fromsolid-js.JSX.Element→Element— Public API types now useElementfromsolid-js(renderer-neutral), matching the Solid 2.0 type model.MultiProvidercleanup — Removed the.Providerfallback branch;Contextis always a function in Solid 2.0.solid-js@^2.0.0-beta.13and@solidjs/web@^2.0.0-beta.13required.1.0.0(major).Noteworthy Solid 2.0 behaviour: context providers now wrap children in a lazy memo (
children(() => props.children)). Tests that previously used barecreateRoot(() => { <Provider/>; })never forced child evaluation. TheMultiProviderbrowser test was updated to userender()so the DOM renderer drives evaluation of the lazy memo chain.New exports
createStrictContextProviderLike
createContextProviderwithout defaults, but with the contract made explicit in types: the hook returnsT(neverT | undefined), and Solid throwsContextNotFoundErrorat runtime when called outside a provider. Accepts an optional{ name }for DevTools labeling.createLayeredContextEach provider extends the parent context value rather than replacing it. The factory receives
(props, parent)whereparentis the nearest enclosing provider's value (falling back todefaultsat the root). You control the merge strategy.Useful for themes, permission layers, i18n patches, and any context where child providers should inherit what they don't explicitly override.
ContextProviderOptions+nameoncreateContextProviderAll three primitives accept
{ name?: string }for the Solid DevTools Symbol label. OncreateContextProviderit's the third argument (with-defaults overload only):